﻿@page "/Axes/LabelsRotation"
@using LiveChartsCore.SkiaSharpView.Blazor
@using LiveChartsCore;
@using LiveChartsCore.Kernel;
@using LiveChartsCore.SkiaSharpView;
@using LiveChartsCore.SkiaSharpView.Painting;
@using SkiaSharp;

<div>
    <input type="range" min="-360" max="720" step="1" @bind="yLabelsRotation" />
    <span>Y Axis Labels Rotation: @yLabelsRotation°</span>
</div>

<CartesianChart
    Series="@series"
    XAxes="@xAxes"
    YAxes="@yAxes">
</CartesianChart>

@code {
    private double[] values = new double[] { 200, 558, 458, 249, 457, 339, 587 };
    private int yLabelsRotation = 15;

    private ISeries[] series;
    private Axis[] xAxes;
    private Axis[] yAxes;

    public LabelsRotation()
    {
        static string tooltipFormat(ChartPoint point) =>
            $"This is {Environment.NewLine}" +
            $"A multi-line label {Environment.NewLine}" +
            $"With a value of {Environment.NewLine}" + point.Coordinate.PrimaryValue;
        static string labeler(double value) =>
            $"This is {Environment.NewLine}" +
            $"A multi-line label {Environment.NewLine}" +
            $"With a value of {Environment.NewLine}" + value * 100;

        series = new ISeries[]
        {
            new LineSeries<double>
            {
                Values = values,
                YToolTipLabelFormatter = tooltipFormat
            }
        };

        xAxes = new Axis[]
        {
            new Axis
            {
                Labeler = labeler,
                MinStep = 1,
                LabelsRotation = 45,
                SeparatorsPaint = new SolidColorPaint(SKColors.LightGray, 2)
            }
        };

        yAxes = new Axis[]
        {
            new Axis
            {
                LabelsRotation = yLabelsRotation,
                Labeler = Labelers.Currency,
                SeparatorsPaint = new SolidColorPaint(SKColors.LightGray, 2)
            }
        };
    }

    protected override void OnParametersSet()
    {
        // Update Y axis rotation dynamically
        yAxes[0].LabelsRotation = yLabelsRotation;
    }
}
